﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Warensoft.Socket.MessageDataStructs
{
    public class Message:IDisposable 
    {
        public short Name { get; set; }
        public short Length { get; set; }
        public List<MemoryStream> Packages { get; set; }
        public Message()
        {
            this.Packages = new List<MemoryStream>();
        }
        public short  PackageCount
        {
            get
            {
                return (short )this.Packages.Count;
            }
           
        }
    
        public byte[] ToBytes()
        {

            MemoryStream ms = new MemoryStream();
            foreach (var package in this.Packages)
            {
                var buffer = package.ToArray();
                ms.Write(buffer ,0,buffer .Length );
                
            }
            return ms.ToArray();
        }

        #region IDisposable Members

        public void Dispose()
        {
            foreach (var strm in this.Packages )
            {
                strm.Close();
            }
        }

        #endregion
    }
}
